#include "dynamicvideoitem.h"
#include "ui_dynamicvideoitem.h"

dynamicvideoitem::dynamicvideoitem(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::dynamicvideoitem)
{
    ui->setupUi(this);

}

dynamicvideoitem::~dynamicvideoitem()
{
    delete ui;
}

void dynamicvideoitem::init()
{
    //创建不断更新界面的定时器
    connect(timer_convert,&QTimer::timeout,this,[=](){
        convert_time+=30;
        if(convert_time>=convert_duration)
        {
            convertlabel();
            convert_time=0;
        }
    });
    timer_convert->start(100);
    //设置每个界面的ui
    QString str="border-image:url("+imageaddress1+")";
    ui->dw1->setStyleSheet(str);
    str="border-image:url("+imageaddress2+")";
    ui->dw2->setStyleSheet(str);
    str="border-image:url("+imageaddress3+")";
   ui->dw3->setStyleSheet(str);
    ui->sign->setText(sign1);
   ui->page1btn->setIcon(QPixmap(":/res/dot_selected .png"));
}

void dynamicvideoitem::convertlabel()
{
    if(cur_image==0)
    {
        ui->stackedWidget->setCurrentIndex(1);
        currentvideoid=videoid1;
        ui->sign->setText(sign2);
    }
    else if(cur_image==1)
    {
        ui->stackedWidget->setCurrentIndex(2);
        ui->sign->setText(sign3);
        currentvideoid=videoid2;
    }
    else
    {
        ui->stackedWidget->setCurrentIndex(0);
        ui->sign->setText(sign1);
        currentvideoid=videoid3;
    }
    cur_image++;
    cur_image%=3;
    changedotui(cur_image);
}

void dynamicvideoitem::changedotui(int curindex)
{
    if(curindex==0)
    {
        ui->page1btn->setIcon(QPixmap(":/res/dot_selected .png"));
        ui->page2btn->setIcon(QPixmap(":/res/dot_noselected .png"));
        ui->page3btn->setIcon(QPixmap(":/res/dot_noselected .png"));
    }
    else if(curindex==1)
    {
        ui->page1btn->setIcon(QPixmap(":/res/dot_noselected .png"));
        ui->page2btn->setIcon(QPixmap(":/res/dot_selected .png"));
        ui->page3btn->setIcon(QPixmap(":/res/dot_noselected .png"));
    }
    else if(curindex==2)
    {
        ui->page1btn->setIcon(QPixmap(":/res/dot_noselected .png"));
        ui->page2btn->setIcon(QPixmap(":/res/dot_noselected .png"));
        ui->page3btn->setIcon(QPixmap(":/res/dot_selected .png"));
    }
}

void dynamicvideoitem::on_nextpage_clicked()
{
    convert_time=0;
    cur_image++;
    cur_image%=3;
    if(cur_image==0)
    {
        ui->stackedWidget->setCurrentIndex(1);
        currentvideoid=videoid1;
        ui->sign->setText(sign2);
    }
    else if(cur_image==1)
    {
        ui->stackedWidget->setCurrentIndex(2);
        ui->sign->setText(sign3);
        currentvideoid=videoid2;
    }
    else
    {
        ui->stackedWidget->setCurrentIndex(0);
        ui->sign->setText(sign1);
        currentvideoid=videoid3;
    }
    changedotui(cur_image);

}


void dynamicvideoitem::on_frontppage_clicked()
{
    convert_time=0;
    cur_image--;
    if(cur_image<0)
        cur_image=2;
    if(cur_image==0)
    {
        ui->stackedWidget->setCurrentIndex(1);
        currentvideoid=videoid1;
        ui->sign->setText(sign2);

    }
    else if(cur_image==1)
    {
        ui->stackedWidget->setCurrentIndex(2);
        ui->sign->setText(sign3);
        currentvideoid=videoid2;

    }
    else
    {
        ui->stackedWidget->setCurrentIndex(0);
        ui->sign->setText(sign1);
        currentvideoid=videoid3;
    }
    changedotui(cur_image);

}

